package com.ljy.controller;

import com.github.pagehelper.PageInfo;
import com.ljy.pojo.*;
import com.ljy.service.AppService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.*;

@Controller
@RequestMapping("/eve")
public class DeveloperController {


    //controller 调用 service 层
    @Autowired
    @Qualifier("AppServiceIMP")
    private AppService service;

    /**
     * APP开发者平台
     *
     * @return
     */
    @RequestMapping("/devlogin")
    public String devlogin() {
        return "devlogin";
    }


    @RequestMapping("/out")
    public String goOut(HttpSession session) {

        session.removeAttribute("user");
        session.removeAttribute("userName");
        System.err.println("当前用户名：" + session.getAttribute("userName"));
        System.err.println("当前用户名对象：" + session.getAttribute("user"));
        System.err.println("退出页面！");
        return "redirect:/eve/devlogin";
    }


    /**
     * 开发者平台登录
     *
     * @return
     */
    @RequestMapping("/Login")
    public String DeveloperLogin(String devCode, String devPassword, Model model, HttpSession session) {

        System.err.println("用户名：" + devCode + ",密码：" + devPassword);

        Dev_user user = service.queryLogin(devCode, devPassword);

        System.err.println("Dev_user==>>" + user);

        if (user == null) {
            model.addAttribute("error", "登录失败！用户或密码错误！");
            return "devlogin";
        }

        session.setAttribute("userName", user.getDevName());
        session.setAttribute("user", user);

        model.addAttribute("user", user);

        return "developer/main";
    }

    /**
     * 点击进入app维护
     *
     * @return
     */
    @RequestMapping("/appinfo")
    public String appinfo(App_info appInfo, Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize) {

        //app状态
        List<Data_dictionary> state = service.appState();
        System.err.println("app状态=>>>>>" + state);
        model.addAttribute("state", state);

        //所属平台
        List<Data_dictionary> their = service.Their();
        System.err.println("所属平台=>>>>" + their);
        model.addAttribute("flatFormList", their);


        //一级分类
        List<App_category> classify1 = service.classify(0);
        System.err.println("一级分类" + classify1);
        model.addAttribute("categoryLevel1List", classify1);
        model.addAttribute("queryCategoryLevel1", appInfo.getCategoryLevel1());


        System.err.println("软件名：" + appInfo.getSoftwareName());
        System.err.println("APP状态：" + appInfo.getStatus());
        System.err.println("所属平台：" + appInfo.getFlatFormId());
        System.err.println("一级分类：" + appInfo.getCategoryLevel1());
        System.err.println("二级分类：" + appInfo.getCategoryLevel2());
        System.err.println("三级分类：" + appInfo.getCategoryLevel3());


        if (appInfo.getCategoryLevel2() != null) {
            //二级分类
            List<App_category> classify2 = service.classify(appInfo.getCategoryLevel1());
            System.err.println("二级分类" + classify2);
            model.addAttribute("categoryLevel2List", classify2);
            model.addAttribute("queryCategoryLevel2", appInfo.getCategoryLevel2());
        }

        if (appInfo.getCategoryLevel3() != null) {
            //三级分类
            List<App_category> classify3 = service.classify(appInfo.getCategoryLevel2());
            System.err.println("三级分类" + classify3);
            model.addAttribute("categoryLevel3List", classify3);
            model.addAttribute("queryCategoryLevel3", appInfo.getCategoryLevel3());
        }


        //分页
        PageInfo<App_info> page = service.findPage(appInfo, pageNum, pageSize);
        System.err.println("查询所有app信息=====>>>" + page);

        model.addAttribute("appInfoList", page);

        model.addAttribute("appInfo", appInfo);

        return "developer/appinfolist";
    }

    /**
     * 二级分类 以及第三级分类
     *
     * @param pid
     * @return
     */
    @RequestMapping("categorylevellist.json")
    @ResponseBody
    public String classify1(int pid) {

        System.err.println("从Ajax传过来的pid=>>>" + pid);

        List<App_category> classify = service.classify(pid);

        String queryCategoryLevel2 = JSON.toJSONString(classify);

        return queryCategoryLevel2;
    }


    /**
     * 跳转到新增APP基础信息页面
     *
     * @return
     */
    @RequestMapping("/appinfoadd")
    public String appinfoadd() {
        return "developer/appinfoadd";
    }


    /**
     * 动态生成所属平台
     *
     * @param tcode
     * @return
     */
    @RequestMapping("datadictionarylist.json")
    @ResponseBody
    public String terrace(String tcode) {

        System.err.println("从Ajax传过来的pid=>>>" + tcode);

        List<Data_dictionary> list = service.queryByPlatform(tcode);
        System.err.println("动态所属平台的值：" + list);
        String terrace = JSON.toJSONString(list);
        System.err.println("转换后的JSON：" + terrace);

        return terrace;
    }

    /**
     * Ajax 验证APKName是否可用
     *
     * @param APKName
     * @return
     */
    @RequestMapping("apkexist.json")
    @ResponseBody
    public String queryAPK(String APKName) {

        System.err.println("从Ajax传过来的APKName:" + APKName);

        Map map = service.queryByAPK(APKName);

        //判断查询出来的APK是否为空
        boolean bo = ObjectUtils.isEmpty(map);

        if (bo) {
            map = new HashMap();
            map.put("APKName", "noexist");//数据库没有该APKName
        } else {
            map.put("APKName", "exist");//数据库有该APKName
        }

        String json = JSON.toJSONString(map);

        return json;
    }


    /**
     * 新增app基本信息方法 以及文件上传
     *
     * @param
     * @return
     */
    @RequestMapping("/add")
    public String add(@RequestParam("logoPicPaths") CommonsMultipartFile file, HttpServletRequest request, Model model, App_info app, HttpSession session) throws IOException {


        //上传路径保存设置
        String path = request.getServletContext().getRealPath("/appFile");
        //如果路径不存在，创建一个
        File realPath = new File(path);
        if (!realPath.exists()) {
            realPath.mkdir();
        }
        System.err.println("上传文件保存地址：" + realPath);

        //通过 CommonsMultipartFile 的方法直接写文件 (注意这个时候)
        file.transferTo(new File(realPath + "/" + file.getOriginalFilename()));

        //拼接绝对路径
        String PicPath = realPath + "/" + file.getOriginalFilename();

        System.out.println("绝对路径：" + PicPath);

        System.out.println("相对路径：/appFile/" + file.getOriginalFilename());

        app.setLogoLocPath(PicPath);//赋值绝对路径
        app.setLogoPicPath("/appFile/" + file.getOriginalFilename());//赋值相对路径

        System.err.println("文件长度: " + file.getSize() + "B");
        System.err.println("文件类型: " + file.getContentType());
        System.err.println("文件原名: " + file.getOriginalFilename());
        System.err.println("========================================");

        System.err.println("开发者编号 当前用户编号:" + app.getDevId());
        System.err.println("创建者 编号:" + app.getCreatedBy());
        System.err.println("软件名称:" + app.getSoftwareName());
        System.err.println("APK名称:" + app.getAPKName());
        System.err.println("支持ROM:" + app.getSupportROM());
        System.err.println("界面语言:" + app.getInterfaceLanguage());
        System.err.println("软件大小:" + app.getSoftwareSize());
        System.err.println("下载次数:" + app.getDownloads());
        System.err.println("所属平台:" + app.getFlatFormId());
        System.err.println("一级分类:" + app.getCategoryLevel1());
        System.err.println("二级分类:" + app.getCategoryLevel2());
        System.err.println("三级分类:" + app.getCategoryLevel3());
        System.err.println("APP状态:" + app.getStatus());
        System.err.println("应用简介:" + app.getAppInfo());
        System.err.println("LOGO图片url路径 相对:" + app.getLogoPicPath());
        System.err.println("LOGO图片的服务器存储路径 绝对:" + app.getLogoLocPath());

        System.err.println("当前app对象的值为：" + app.toString());

        int add = service.add(app);//添加方法

        //判断添加方法返回出来的值
        if (add > 0) {
            System.err.println("添加成功！");
        } else {
            System.err.println("添加失败！");
        }

        return "redirect:/eve/appinfo";//重定向到@RequestMapping("/appinfo")请求;
    }

    /**
     * 新增app版本
     *
     * @param id
     * @return
     */
    @RequestMapping("/appversionadd/{id}")
    public String appversionadd(@PathVariable("id") Integer id, Model model, HttpSession session) {

        System.out.println("当前传过来的编号为： " + id);

        List appVersions = service.queryByVersion(id);

        System.out.println("根据传参过来的编号查询：" + appVersions);

        session.setAttribute("appVersion1", appVersions);
        model.addAttribute("appid", id);
        return "developer/appversionadd";
    }

    /**
     * 添加 版本
     *
     * @param appVersion
     * @return
     */
    @RequestMapping("/addByApp_version")
    public String addByApp_version(HttpSession session, App_version appVersion, @RequestParam("a_downloadLink") CommonsMultipartFile file, HttpServletRequest request, Model model) throws IOException {

        //上传路径保存设置
        String path = request.getServletContext().getRealPath("/appFile");
        //如果路径不存在，创建一个
        File realPath = new File(path);
        if (!realPath.exists()) {
            realPath.mkdir();
        }
        System.err.println("上传文件保存地址：" + realPath);

        //通过 CommonsMultipartFile 的方法直接写文件 (注意这个时候)
        file.transferTo(new File(realPath + "/" + file.getOriginalFilename()));

        //拼接绝对路径
        String PicPath = realPath + "/" + file.getOriginalFilename();

        System.err.println("绝对路径：" + PicPath);

        System.err.println("相对路径：/appFile/" + file.getOriginalFilename());
        System.err.println("文件名：" + file.getOriginalFilename());
        appVersion.setApkLocPath(PicPath);//赋值存储在服务器路径（数据库）
        appVersion.setDownloadLink("/appFile/" + file.getOriginalFilename());//下载地址
        appVersion.setApkFileName(file.getOriginalFilename());//赋值文件名
        System.err.println("当前app编号：" + appVersion.getAppId());
        System.err.println("版本号：" + appVersion.getVersionNo());
        System.err.println("版本大小：" + appVersion.getVersionSize());
        System.err.println("发布状态：" + appVersion.getPublishStatus());
        System.err.println("版本简介：" + appVersion.getVersionInfo());
        System.err.println("存储服务器位置：" + appVersion.getApkLocPath());
        System.err.println("文件名：" + appVersion.getApkFileName());
        System.err.println("创建者编号：" + appVersion.getCreatedBy());
        System.err.println("下载链接：" + appVersion.getDownloadLink());


        int version = service.addByApp_version(appVersion);


        if (version > 0) {
            System.err.println("添加成功！");
        } else {
            System.err.println("添加失败！");
        }
        System.err.println("最新版本编号：" + appVersion.getId());

        int updataByVersionId = service.updataByVersionId(appVersion.getId(), appVersion.getAppId());

        if (updataByVersionId > 0) {
            System.err.println("修改最新版本成功！");
        } else {
            System.err.println("修改最新版本失败！");
        }
        return "redirect:/eve/appinfo";
    }

    /**
     * 查看当前app信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/appview/{id}")
    public String appinfoview(@PathVariable("id") Integer id, Model model, HttpSession session) {

        System.err.println("当前查看编号：" + id);

        Map appInfo = service.queryByAppinfo(id);

        model.addAttribute("appInfo", appInfo);


        List appVersions = service.queryByVersion(id);

        System.out.println("根据传参过来的编号查询：" + appVersions);

        session.setAttribute("appVersions2", appVersions);

        return "developer/appinfoview";
    }

    /**
     * 查看返回
     *
     * @return
     */
    @RequestMapping("/list")
    public String back() {
        return "redirect:/eve/appinfo";
    }

    /**
     * 跳转至修改版本
     *
     * @param versionid
     * @param appinfoid
     * @return
     */
    @RequestMapping("/versionmodify/{versionid}/{appinfoid}")
    public String appversionmodify(@PathVariable("versionid") Integer versionid, @PathVariable("appinfoid") Integer appinfoid, HttpSession session, Model model) {

        System.err.println("当前Ajax传过来的数据为=========》》》》》最新版本编号：" + versionid + ",app编号：" + appinfoid);

        List appVersions = service.queryByVersion(appinfoid);

        System.out.println("根据传参过来的编号查询：" + appVersions);

        session.setAttribute("appVersions3", appVersions);

        Map map = service.queryApp_versionById(versionid, appinfoid);
        System.err.println("返回Map集合的值：" + map);

        model.addAttribute("appVersionMap", map);

        return "/developer/appversionmodify";
    }


    /**
     * 修改版本
     *
     * @return
     */
    @RequestMapping("/updataVersionmodify")
    public String updataVersionmodify(App_version appVersion, @RequestParam("apkLocPath_File") MultipartFile file, HttpServletRequest request, HttpSession session) throws IOException {
        System.err.println("进入了修改版本方法！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！");
        System.err.println("----------------》》》》》！！！！！！！！》》》》》》》》文件名：" + file.getOriginalFilename());

        //在不修改apk的情况下 针对文件 做不修改文件
        if (file.getOriginalFilename().length() == 0) {

            System.err.println("文件为空时进来！：" + file.getOriginalFilename());

            int updataByApp_version2 = service.updataByApp_version2(appVersion);

            if (updataByApp_version2 > 0) {
                System.err.println("修改成功！");
            } else {
                System.err.println("修改失败！");
            }
        } else {


            //上传路径保存设置
            String path = request.getServletContext().getRealPath("/appFile");
            //如果路径不存在，创建一个
            File realPath = new File(path);
            if (!realPath.exists()) {
                realPath.mkdir();
            }
            System.err.println("上传文件保存地址：" + realPath);

            //通过 CommonsMultipartFile 的方法直接写文件 (注意这个时候)
            file.transferTo(new File(realPath + "/" + file.getOriginalFilename()));

            //拼接绝对路径
            String PicPath = realPath + "/" + file.getOriginalFilename();

            System.err.println("绝对路径：" + PicPath);

            System.err.println("相对路径：/appFile/" + file.getOriginalFilename());
            System.err.println("文件名：" + file.getOriginalFilename());

            appVersion.setDownloadLink("/appFile/" + file.getOriginalFilename());//下载地址
            appVersion.setApkLocPath(PicPath);//绝对地址
            appVersion.setApkFileName(file.getOriginalFilename());//当前文件名
            System.err.println("版本编号：" + appVersion.getId());
            System.err.println("当前登录用户编号：" + appVersion.getModifyBy());
            System.err.println("版本号：" + appVersion.getVersionNo());
            System.err.println("版本大小：" + appVersion.getVersionSize());
            System.err.println("发布状态：" + appVersion.getPublishStatus());
            System.err.println("版本简介：" + appVersion.getVersionInfo());
            System.err.println("下载链接：" + appVersion.getDownloadLink());
            System.err.println("apk文件的服务器存储路径：" + appVersion.getApkLocPath());
            System.err.println("上传的apk文件名称：" + appVersion.getApkFileName());

            int updata = service.updataByApp_version(appVersion);

            if (updata > 0) {
                System.err.println("修改成功！");
            } else {
                System.err.println("修改失败！");
            }

        }
        return "redirect:/eve/appinfo";
    }


    /**
     * 删除APK
     *
     * @return0
     */
    @RequestMapping("/delfile")
    @ResponseBody
    public String dataAPK(int id) {

        System.err.println("当前从Ajax传过来的数据：编号：" + id);

        App_version appVersion = service.queryByID(id);

        System.err.println("根据编号查询出来的数据：" + appVersion);

        File file = new File(appVersion.getApkLocPath());

        System.err.println("=[]=====-[]=[]=[]---------------->>>>" + file);
        System.err.println("=[]=====-[]=[]=[]---------------->>>>" + file.isFile());
        System.err.println("=[]=====-[]=[]=[]---------------->>>>" + file.exists());
        //创建mao集合 用于设置Ajax判断条件
        Map map = new HashMap();

        if (file.isFile() == true && file.exists() == true) {

            file.delete();//删除文件夹里面的文件

            System.err.println("=[]=====-[]=[]=[]-----是否删除成功---------->>>>" + file.delete());

            int updataFile = service.updataFile(id);

            //判断查询出来的APK是否为空
            boolean bo = ObjectUtils.isEmpty(updataFile);
            System.err.println("判断出来值为：" + bo);

            //判断没有数据
            if (!bo) {
                map.put("result", "success");
                System.err.println("文件删除成功！");
            }
        } else {
            map.put("result", "failed");
            System.err.println("-----------------》》》删除文件失败！《《《---------");
            System.err.println("LOGO删除失败！");
        }
        //转换为JSON格式
        String jsonFIle = JSON.toJSONString(map);

        return jsonFIle;
    }


    /**
     * 删除LOGO
     *
     * @return0
     */
    @RequestMapping("/delfileByInfo")
    @ResponseBody
    public String dataLOGO(Integer id) {

        System.err.println("当前从Ajax传过来的数据：编号：" + id);

        App_info app_info = service.queryByApp_infoAllById(id);

        System.err.println("根据编号查询出来的数据：" + app_info);
        System.err.println("根据编号查询出来的数据：" + app_info.getLogoLocPath());

        File file = new File(app_info.getLogoLocPath());

        System.err.println("=[]=====-[]=[]=[]---------------->>>>" + file);
        System.err.println("=[]=====-[]=[]=[]--------isFile判断为-------->>>>" + file.isFile());
        System.err.println("=[]=====-[]=[]=[]------exists判断为---------->>>>" + file.exists());
        //创建mao集合 用于设置Ajax判断条件
        Map map = new HashMap();

        if (file.isFile() == true && file.exists() == true) {

            file.delete();//删除文件夹里面的文件

            System.err.println("=[]=====-[]=[]=[]-----是否删除成功---------->>>>" + file.delete());

            int dataLOGO = service.dataLOGO(id);

            //判断查询出来的APK是否为空
            boolean bo = ObjectUtils.isEmpty(dataLOGO);
            System.err.println("判断出来值为：" + bo);

            //判断没有数据
            if (!bo) {
                map.put("result", "success");
                System.err.println("LOGO删除成功！");
            }
        } else {
            map.put("result", "failed");
            System.err.println("-----------------》》》删除文件失败！《《《---------");
            System.err.println("LOGO删除失败！");
        }
        //转换为JSON格式
        String jsonFIle = JSON.toJSONString(map);

        return jsonFIle;
    }

    /**
     * 跳转至修改APP基础信息
     */
    @RequestMapping("/infomodify/{appinfoid}")
    public String infomodify(@PathVariable("appinfoid") int appinfoid, Model model) {

        System.err.println("当前传过来的编号：" + appinfoid);

        Map map = service.queryApp_infoById(appinfoid);

        System.err.println("根据编号查询出来的数据：" + map);

        model.addAttribute("mapInfo", map);

        return "/developer/appinfomodify";
    }


    /**
     * 修改app信息
     *
     * @return
     */
    @RequestMapping("/updataInfomodifys")
    public String updataInfomodify(Integer status, App_info appInfo, @RequestParam("attach") MultipartFile file, HttpServletRequest request) throws IOException {

        System.err.println("进入了修改app信息方法！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！");
        System.err.println("----------------》》》》》！！！！！！！！》》》》》》》》文件名：" + file.getOriginalFilename());

        //在不修改apk的情况下 针对文件 做不修改文件
        if (file.getOriginalFilename().length() == 0) {

            System.err.println("文件为空时进来！：" + file.getOriginalFilename());

            int updataApp_infoById2 = service.updataApp_infoById2(appInfo);

            if (updataApp_infoById2 > 0) {
                System.err.println("修改成功！");
            } else {
                System.err.println("修改失败！");
            }
        } else {

            //上传路径保存设置
            String path = request.getServletContext().getRealPath("/appFile");
            //如果路径不存在，创建一个
            File realPath = new File(path);
            System.err.println("----------------------------->>>>" + realPath.exists());
            System.err.println("=[]=====-[]=[]=[]--------file-------->>>>" + file);
            System.err.println("=[]=====-[]=[]=[]------exists判断为---------->>>>" + realPath.exists());
            System.err.println("=[]=====-[]=[]=[]------filename是否为空---------->>>>" + file.getOriginalFilename());


            if (realPath.exists() == true) {
                realPath.mkdir();
            }
            System.err.println("上传文件保存地址：" + realPath);

            //通过 CommonsMultipartFile 的方法直接写文件 (注意这个时候)
            file.transferTo(new File(realPath + "/" + file.getOriginalFilename()));

            //拼接绝对路径
            String PicPath = realPath + "/" + file.getOriginalFilename();

            System.err.println("绝对路径：" + PicPath);

            System.err.println("相对路径：/appFile/" + file.getOriginalFilename());
            System.err.println("文件名：" + file.getOriginalFilename());
            appInfo.setLogoLocPath(PicPath);//赋值绝对路径
            appInfo.setLogoPicPath("/appFile/" + file.getOriginalFilename());//赋值相对路径


            System.err.println("文件长度: " + file.getSize() + "B");
            System.err.println("文件类型: " + file.getContentType());
            System.err.println("文件原名: " + file.getOriginalFilename());
            System.err.println("========================================");

            System.err.println("更新者编号 当前用户编号:" + appInfo.getModifyBy());
            System.err.println("app 编号:" + appInfo.getId());
            System.err.println("软件名称:" + appInfo.getSoftwareName());
            System.err.println("APK名称:" + appInfo.getAPKName());
            System.err.println("支持ROM:" + appInfo.getSupportROM());
            System.err.println("界面语言:" + appInfo.getInterfaceLanguage());
            System.err.println("软件大小:" + appInfo.getSoftwareSize());
            System.err.println("下载次数:" + appInfo.getDownloads());
            System.err.println("所属平台:" + appInfo.getFlatFormId());
            System.err.println("一级分类:" + appInfo.getCategoryLevel1());
            System.err.println("二级分类:" + appInfo.getCategoryLevel2());
            System.err.println("三级分类:" + appInfo.getCategoryLevel3());
            System.err.println("APP状态:" + appInfo.getStatus());
            System.err.println("应用简介:" + appInfo.getAppInfo());
            System.err.println("LOGO图片url路径 相对:" + appInfo.getLogoPicPath());
            System.err.println("LOGO图片的服务器存储路径 绝对:" + appInfo.getLogoLocPath());
            System.err.println("保存并再次提交审核:" + status);


            if (status == 1) {
                appInfo.setStatus(status);
                System.err.println("------->> 重新赋值并提交！<<-----" + appInfo.getStatus());
            }

            int infoById = service.updataApp_infoById(appInfo);

            if (infoById > 0) {
                System.out.println("修改才成功！");

            } else {
                System.out.println("修改失败！");
            }

        }
        return "redirect:/eve/appinfo";
    }

    /**
     * 删除app方法
     *
     * @return
     */
    @RequestMapping("/delapp")
    @ResponseBody
    public String delapp(Integer id) {
        Map map = new HashMap();

        System.err.println("---------------->>需要删除的编号：" + id);

        App_info app_info = service.queryByApp_infoAllById(id);

        System.err.println("--------------------->>>>>>>>>>>------------->>>>>>>>" + app_info);

        if (app_info == null) {

            map.put("delResult", "notexist");

        } else {

            System.err.println("-----------------》》》当前状态：" + app_info.getStatus() + "《《《---------");

            if (app_info.getStatus() != 2 || app_info.getStatus() != 4 || app_info.getStatus() != 5) {

                map.put("delResult", "false");
                System.err.println("-----------------》》》删除文件失败！《《《---------");

            } else {


                File file = new File(app_info.getLogoLocPath());

                System.err.println("=[]=====-[]=[]=[]---------------->>>>" + file);
                System.err.println("=[]=====-[]=[]=[]--------isFile判断为-------->>>>" + file.isFile());
                System.err.println("=[]=====-[]=[]=[]------exists判断为---------->>>>" + file.exists());

                if (file.isFile() == true && file.exists() == true) {

                    file.delete();//删除文件夹里面的文件
                    System.err.println("=[]=====-[]=[]=[]-----是否删除成功---------->>>>" + file.delete());

                    int delete = service.deleteByApp_info(id);
                    //判断查询出来的APK是否为空
                    boolean bo = ObjectUtils.isEmpty(delete);
                    System.err.println("判断出来值为：" + bo);

                    //判断没有数据
                    if (!bo) {
                        map.put("result", "success");
                        map.put("delResult", "true");
                    }
                } else {

                    System.err.println("-----------------》》》当前状态：" + app_info.getStatus() + "《《《---------");

                         map.put("delResult", "false");
                        System.err.println("-----------------》》》删除文件失败！《《《---------");
                }
            }
        }
        String jsons = JSON.toJSONString(map);

        return jsons;
    }


    /**
     * 上架
     * 下架
     *
     * @return
     */
    @RequestMapping("/sale/{id}/{saleSwitch}")
    @ResponseBody
    public String context(@PathVariable("id") Integer id, @PathVariable("saleSwitch") String saleSwitch) {

        System.err.println("app信息编号：" + id + ",上架为（open）/ 下架（close）:-----》》" + saleSwitch);

        Map map = new HashMap();

        if (saleSwitch.equals("open")) {

            map.put("errorCode", "0");
            int status = service.updataByStatus(4, id);

            if (status > 0) {
                map.put("resultMsg", "success");
                System.out.println("上架成功！");
            } else {
                map.put("resultMsg", "failed");
                System.out.println("上架失败！");
            }

        } else if (saleSwitch.equals("close")) {

            map.put("errorCode", "0");
            int status = service.updataByStatus(5, id);

            if (status > 0) {
                map.put("resultMsg", "success");
                System.out.println("下架成功！");
            } else {
                map.put("resultMsg", "failed");
                System.out.println("下架失败！");
            }

        } else {
            map.put("errorCode", "1");
        }

        String jsons = JSON.toJSONString(map);

        return jsons;
    }


}
